const prefix = import.meta.env.VITE_CSS_PREFIX || "dzq-";

const useCssNamespace = (name: string) => {
  const state = {
    block: "",
    suffix: ""
  };
  const returnState = {
    state,
    block(blockName: string) {
      state.block = blockName;
      return returnState;
    },
    suffix(suffix: string) {
      state.suffix = suffix;
      return returnState;
    },
    e() {
      let result = prefix + name;
      if (state.block) {
        result += `-${state.block}`;
      }
      if (state.suffix) {
        result += `__${state.suffix}`;
      }
      Object.assign(state, {
        block: "",
        suffix: ""
      });
      return result;
    },
    predicate(v: boolean) {
      if (!v) return "";
      return this.e();
    }
  };
  return returnState;
};

export default useCssNamespace;
